package wqh.dao.impl;

import org.hibernate.Session;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;
import wqh.dao.WaterChannelAlarmLogDao;
import wqh.domain.WaterChannelAlarmLog;

/**
 * Created by wqh on 2017/1/14.
 */
@Repository("waterChannelAlarmLogDao")
public class WaterChannelAlarmLogDaoImpl extends DaoImpl<WaterChannelAlarmLog> implements WaterChannelAlarmLogDao {

    @Override
    public Long countByTimeRange(Integer start, Integer end) {
        Session session = this.getSessionFactory().getCurrentSession();
        String hql = "SELECT COUNT(*) FROM WaterChannelAlarmLog w WHERE  w.alarm_time BETWEEN :start AND :end";
        Query query = session.createQuery(hql);
        query.setParameter("start",start);
        query.setParameter("end",end);
        return  query.uniqueResult() == null ? 0 : (Long) query.uniqueResult();
    }
}
